//本模块为临时演示数据，最后建议删去
import store from "@/store";
import crudSection from "@/api/buss/sectionInfo";
import msgUtil from "@/utils/msgUtil";
export function getWorkbenchList(param) {
  console.log("getWorkbenchList", param)
  return new Promise((resolve, reject) => {
    let data = {}
    data.contractSum = 364.2
    data.measureSum = 168.9
    data.list = []
    if (param.projectId) {
      data.list = [{
          name: "JL01",
          contractSum: 282260,
          measureSum: 128630,
        },
        {
          name: "JL02",
          contractSum: 255560,
          measureSum: 155530,
        },
        {
          name: "JL03",
          contractSum: 233360,
          measureSum: 133330,
        }
      ]
    } else {
      data.list = [{
          name: "镜水路北段",
          contractSum: 4700,
          measureSum: 3200,
        },
        {
          name: "城投人才公寓",
          contractSum: 4100,
          measureSum: 2200,
        },
        {
          name: "329国道",
          contractSum: 3100,
          measureSum: 1800,
        },
        {
          name: "柯诸高速",
          contractSum: 3700,
          measureSum: 2200,
        },
        {
          name: "尹大线改造",
          contractSum: 4500,
          measureSum: 3800,
        },
        {
          name: "北环快速通道",
          contractSum: 4200,
          measureSum: 2800,
        },
        {
          name: "永兴路",
          contractSum: 4800,
          measureSum: 3800,
        }
      ]
    }
    let res = {
      code: 200,
      data: data,
    }
    resolve(res)
  })
}

function randConstructionList(projectId) {
  let list = []
  if (projectId) {
    for (let i = 1; i <= 12; i++) {
      list.push({
        name: i + "月",
        thisPeriodAmount: 2500 + Math.round(Math.random() * 500),
        measureSum: 1500 + Math.round(Math.random() * 1500),
        contractAmount: 3000 + Math.round(Math.random() * 1000),
      })
    }
  } else {
    list = [{
        name: "镜水路北段",
      thisPeriodAmount: 1000 + Math.round(Math.random() * 1000),
      measureSum: Math.round(Math.random() * 2000),
      contractAmount: 2000 + Math.round(Math.random() * 3000),
      },
      {
        name: "城投人才公寓",
        thisPeriodAmount: 1000 + Math.round(Math.random() * 1000),
        measureSum: Math.round(Math.random() * 2000),
        contractAmount: 2000 + Math.round(Math.random() * 3000),
      },
      {
        name: "329国道",
        thisPeriodAmount: 1000 + Math.round(Math.random() * 1000),
        measureSum: Math.round(Math.random() * 2000),
        contractAmount: 2000 + Math.round(Math.random() * 3000),
      },
      {
        name: "柯诸高速",
        thisPeriodAmount: 1000 + Math.round(Math.random() * 1000),
        measureSum: Math.round(Math.random() * 2000),
        contractAmount: 2000 + Math.round(Math.random() * 3000),
      },
      {
        name: "尹大线改造",
        thisPeriodAmount: 1000 + Math.round(Math.random() * 1000),
        measureSum: Math.round(Math.random() * 2000),
        contractAmount: 2000 + Math.round(Math.random() * 3000),
      },
      {
        name: "北环快速通道",
        thisPeriodAmount: 1000 + Math.round(Math.random() * 1000),
        measureSum: Math.round(Math.random() * 2000),
        contractAmount: 2000 + Math.round(Math.random() * 3000),
      },
      {
        name: "永兴路",
        thisPeriodAmount: 1000 + Math.round(Math.random() * 1000),
        measureSum: Math.round(Math.random() * 2000),
        contractAmount: 2000 + Math.round(Math.random() * 3000),
      }
    ]
  }
  return list
}

export function getConstructionData(param) {
  return new Promise(async (resolve, reject) => {
    let {
      projectId,
      month
    } = param
    let data = []
    if (projectId) { //单项目
      let postData = {
        project: projectId,
        code: "",
        pageNo: 0,
        pageSize: 10,
      }
      await crudSection.getTablePage(postData).then(res => {
        if (res.status == 1) {
          if (res.list.length > 0) {
            data = res.list

            data.forEach(item => {
              item.measureSum = 5 + Math.round(Math.random() * 5)
              item.contractAmount = 2000 + Math.round(Math.random() * 1000),
                item.list = randConstructionList(projectId)

            })
          }
          console.log(data)
        } else {
          msgUtil.error2(res.data.message)
        }
      })

    } else { //多项目
      data = [{
          name: "本月施工计量",
          measureSum: 1456.3,
          contractAmount: 2000,
          list: randConstructionList(projectId)
        },
        {
          name: "本年施工计量",
          measureSum: 13338.2,
          contractAmount: 20000,
          list: randConstructionList(projectId)
        },
        {
          name: "累计施工计量",
          measureSum: 14558.6,
          contractAmount: 80000,
          list: randConstructionList(projectId)
        }
      ]
    }
    let res = {
      code: 200,
      data: data,
    }
    resolve(res)
  })
}


export function getProjecChangeList(type) {
  // type = 累计 | 本年 | 本季
  return new Promise((resolve, reject) => {
    let data = []
    let projectsArr = JSON.parse(sessionStorage.getItem("projectsArr"))
    if(store.state.settings.changeHeaderProject){
      data.push(projectsArr.find(item => item.id === store.state.settings.changeHeaderProject));
    }else {
      data = projectsArr.filter(item => item.id) ;
    }
    console.log(sessionStorage.getItem("projectsArr"))
    console.log("data====",data)

    let list = []
    data.forEach(item => {
      list.push({
        name: item.name,
        changeCount: 10 + Math.round(Math.random() * 10),
        approvalCount: 5 + Math.round(Math.random() * 5),
        changeAmount: 3000 + Math.round(Math.random() * 3000),
        approvalAmount: 2000 + Math.round(Math.random() * 1000),

        change1Count: 10 + Math.round(Math.random() * 10),
        approval1Count: 5 + Math.round(Math.random() * 5),
        change1Amount: 3000 + Math.round(Math.random() * 3000),
        approval1Amount: 2000 + Math.round(Math.random() * 1000),

        change2Count: 10 + Math.round(Math.random() * 10),
        approval2Count: 5 + Math.round(Math.random() * 5),
        change2Amount: 3000 + Math.round(Math.random() * 3000),
        approval2Amount: 2000 + Math.round(Math.random() * 1000),
      })
    })

    let res = {
      code: 200,
      data: list,
    }
    resolve(res)
  })
}

export function serviceContractMeasure(param) {
  return new Promise((resolve, reject) => {
    let data = [{
        "type": "勘察设计合同",
        "amount": 2762.210979,
        "payAmount": 2172.72,
        "list": [{
            "number": "城投人才公寓",
            "title": "城投人才公寓",
            "amount": 2572.43,
            "measureAmount": 2367.72,
            "rate": 0.0263
          },
          {
            "number": "329国道改建",
            "title": "329国道改建",
            "amount": 100.00,
            "measureAmount": 90,
            "rate": 0.2
          }
        ]
      },
      {
        "type": "征拆合同",
        "amount": 5528.891925,
        "payAmount": 10.69,
        "list": [{
            "number": "合同201",
            "title": "镜水路北段",
            "amount": 5516.45,
            "measureAmount": 5228.95,
            "rate": 0.0016
          },
          {
            "number": "合同202",
            "title": "城投人才公寓",
            "amount": 300.00,
            "measureAmount": 250,
            "rate": 0.2
          },
          {
            "number": "合同203",
            "title": "329国道",
            "amount": 300.00,
            "measureAmount": 150,
            "rate": 0.5
          },
          {
            "number": "合同204",
            "title": "柯诸高速",
            "amount": 12.45,
            "measureAmount": 1.74,
            "rate": 0.1398
          },
          {
            "number": "合同205",
            "title": "尹大线改造",
            "amount": 100.00,
            "measureAmount": 25,
            "rate": 0.25
          },
          {
            "number": "合同206",
            "title": "北环快速通道",
            "amount": 100.00,
            "measureAmount": 36,
            "rate": 0.36
          },
          {
            "number": "合同207",
            "title": "永兴路",
            "amount": 200.00,
            "measureAmount": 60,
            "rate": 0.3
          }
        ]
      },
      {
        "type": "咨询合同",
        "amount": 1533.472043,
        "payAmount": 792.86,
        "list": [{
            "number": "合同301",
            "title": "镜水路北段",
            "amount": 1533.47,
            "measureAmount": 1492.86,
            "rate": 0.5170
          },
          {
            "number": "合同302",
            "title": "城投人才公寓",
            "amount": 30.00,
            "measureAmount": 26,
            "rate": 0.333
          },
          {
            "number": "合同303",
            "title": "329国道",
            "amount": 320.00,
            "measureAmount": 160,
            "rate": 0.5
          },
          {
            "number": "合同304",
            "title": "柯诸高速",
            "amount": 50.00,
            "measureAmount": 40,
            "rate": 0.8
          },
          {
            "number": "合同305",
            "title": "尹大线改造",
            "amount": 60.00,
            "measureAmount": 30,
            "rate": 0.5
          },
          {
            "number": "合同306",
            "title": "北环快速通道",
            "amount": 100.00,
            "measureAmount": 70,
            "rate": 0.7
          },
          {
            "number": "合同307",
            "title": "永兴路",
            "amount": 100.00,
            "measureAmount": 40,
            "rate": 0.4
          }
        ]
      },
      {
        "type": "征拆合同",
        "amount": 1687.961325,
        "payAmount": 99.75,
        "list": [{
            "number": "合同401",
            "title": "镜水路北段",
            "amount": 1687.96,
            "measureAmount": 1599.75,
            "rate": 0.0591
          },
          {
            "number": "合同402",
            "title": "城投人才公寓",
            "amount": 400.00,
            "measureAmount": 350,
            "rate": 0.1
          },
          {
            "number": "合同403",
            "title": "329国道",
            "amount": 400.00,
            "measureAmount": 200,
            "rate": 0.5
          },
          {
            "number": "合同404",
            "title": "柯诸高速",
            "amount": 40.00,
            "measureAmount": 40,
            "rate": 1
          },
          {
            "number": "合同405",
            "title": "尹大线改造",
            "amount": 300.00,
            "measureAmount": 60,
            "rate": 0.2
          },
          {
            "number": "合同406",
            "title": "北环快速通道",
            "amount": 500.00,
            "measureAmount": 250,
            "rate": 0.5
          },
          {
            "number": "合同407",
            "title": "永兴路",
            "amount": 60.00,
            "measureAmount": 30,
            "rate": 0.5
          }
        ]
      }
    ]

    let res = {
      code: 200,
      data: data,
    }
    resolve(res)
  })
}
